{% if response.HasType -%}
{%     if response.IsFile -%}
{%         if response.IsSuccess -%}
var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
var fileResponse_ = new FileResponse((int)response_.StatusCode, headers_, responseStream_, {% if InjectHttpClient %}null{% else %}client_{% endif %}, response_); 
client_ = null; response_ = null; // response and client are disposed by FileResponse
return fileResponse_;
{%         else -%}
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); 
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", (int)response_.StatusCode, responseData_, headers_, null);
{%         endif -%}
{%     else -%}
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); 
var result_ = default({{ response.Type }}); 
try
{
{%    if response.IsPlainText -%}
    result_ = ({{ response.Type }})System.Convert.ChangeType(responseData_, typeof({{ response.Type }}));
{%    else -%}
    result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<{{ response.Type }}>(responseData_, _settings.Value);
{%    endif -%}
{%         if response.IsSuccess -%}
{%             if operation.WrapResponse -%}
    return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>((int)response_.StatusCode, headers_, result_); 
{%             else -%}
    return result_; 
{%             endif -%}
{%         endif -%}
} 
catch (System.Exception exception_) 
{
    throw new {{ ExceptionClass }}("Could not deserialize the response body.", (int)response_.StatusCode, responseData_, headers_, exception_);
}
{%         if response.IsSuccess == false -%}
{%             if response.InheritsExceptionSchema -%}
if (result_ == null)
    result_ = new {{ response.Type }}();
result_.Data.Add("HttpStatus", status_);
result_.Data.Add("HttpHeaders", headers_);
result_.Data.Add("HttpResponse", responseData_);
{%                 if WrapDtoExceptions -%}
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", (int)response_.StatusCode, responseData_, headers_, result_, result_);
{%                 else -%}
throw result_;
{%                 endif -%}
{%             else -%}
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", (int)response_.StatusCode, responseData_, headers_, result_, null);
{%             endif -%}
{%         endif -%}
{%     endif -%}
{% elseif response.IsSuccess -%}
{%     if operation.HasResultType -%}
{%         if operation.WrapResponse -%}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>((int)response_.StatusCode, headers_, default({{ operation.UnwrappedResultType }})); 
{%         else -%}
return default({{ operation.UnwrappedResultType }});
{%         endif -%}
{%     else -%}
{%         if operation.WrapResponse -%}
return new {{ ResponseClass }}((int)response_.StatusCode, headers_); 
{%         else -%}
return;
{%         endif -%}
{%     endif -%}
{% else -%}
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); 
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", (int)response_.StatusCode, responseData_, headers_, null);
{% endif -%}